package com.sgb.kjwl.view.ui.adapter.self

import android.content.Context
import androidx.databinding.DataBindingUtil
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CircleCrop
import com.bumptech.glide.request.RequestOptions
import com.sgb.kjwl.R
import com.sgb.kjwl.databinding.ItemOrganizationAuthListBinding
import com.sgb.kjwl.model.entity.self.OrganizationAuthEntity
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter
import com.swgk.core.recyclerview.adapter.ItemViewHolder


class OrganizationAuthListAdapter(context : Context,  layoutId : Int, datas : List<OrganizationAuthEntity>?) : BaseRecycleAdapter<OrganizationAuthEntity>(context, layoutId, datas){

    private var mBinding : ItemOrganizationAuthListBinding ?= null

    override fun convert(holder: ItemViewHolder?, item : OrganizationAuthEntity?) {
         mBinding = DataBindingUtil.bind(holder!!.itemView)
         if (mBinding != null){
             mBinding!!.viewModel = item
             mBinding!!.executePendingBindings()
             if (item!!.status == 1) {//待审核
                 mBinding!!.tvStatus.text = "审核中"
                 mBinding!!.tvStatus.setBgColor(R.color.color_secondary_blue)
             } else if (item.status == 2) {//审核通过
                 mBinding!!.tvStatus.text = "认证失败"
                 mBinding!!.tvStatus.setBgColor(R.color.color_third_red_easy)
             } else if (item.status == 3){
                 mBinding!!.tvStatus.text = "已认证"
                 mBinding!!.tvStatus.setBgColor(R.color.color_secondary_green)
             }
             val optionsTeam = RequestOptions()
                 .placeholder(R.drawable.icon_team_default) //图片加载出来前，显示的图片
                 .fallback(R.drawable.icon_team_default) //url为空的时候,显示的图片
                 .apply(RequestOptions.bitmapTransform(CircleCrop())) //裁剪圆形
                 .error(R.drawable.icon_team_default) //图片加载失败后，显示的图片

             Glide.with(context).load(item.codeCertificatePic).apply(optionsTeam).into(mBinding!!.img)
         }
    }
}